package future;

import com.google.common.util.concurrent.*;
import org.checkerframework.checker.nullness.qual.Nullable;

public class Test05 {
    public static void main(String[] args) {
        ListeningExecutorService service = MoreExecutors.newDirectExecutorService();
        ListenableFuture<String> future1 = service.submit(() -> "2019-11-21 setting front of computer,felling bad.");
        //ListenableFuture<Integer> future2 = Futures.transform(future1, String::length, service);
        ListenableFuture<Integer> future3 = Futures.transformAsync(future1, input -> Futures.immediateFuture(input.length()), service);
        Futures.addCallback(future3, new FutureCallback<>() {
            @Override
            public void onSuccess(@Nullable Integer integer) {
                System.out.println(integer);
            }

            @Override
            public void onFailure(Throwable throwable) {
                throwable.printStackTrace();
            }
        }, service);
    }
}
